/*******************************************************************************
 * Copyright (c) 2003 Boris Pruessmann and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Common Public License v0.5 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.core.internal.api;

import java.util.Map;

import net.sourceforge.perforce.api.IError;
import net.sourceforge.perforce.api.IPerforceCommand;
import net.sourceforge.perforce.core.IClientUserListener;

import org.eclipse.core.runtime.IStatus;

/**
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
public class ClientUserListenerDelegate implements IPerforceCommand {
  // ---------------------------------------------------------------------------
  // Private Variables

  /** Stores the delegate object. */
  private final IPerforceCommand delegate;
  /** Stores the listeners. */
  private final IClientUserListener[] listeners;

  //----------------------------------------------------------------------------
  // ---- Constructors

  /** Constructor for ClientUserListenerDelegate. */
  ClientUserListenerDelegate(IPerforceCommand theDelegate, IClientUserListener[] theListeners) {
    delegate = theDelegate;
    listeners = theListeners;
  }

  //----------------------------------------------------------------------------
  // -- Public Methods

  public void finished() {
    for (int i = 0; i < listeners.length; i++) {
      listeners[i].finished(delegate);
    }

    delegate.finished();
  }

  public boolean handleError(IError error) {
    for (int i = 0; i < listeners.length; i++) {
      listeners[i].handleError(delegate, error);
    }

    return delegate.handleError(error);
  }

  public String inputData(IError error) {
    return delegate.inputData(error);
  }

  public boolean message(IError error) {
    return delegate.message(error);
  }

  public void outputBinary(byte[] data) {
    delegate.outputBinary(data);
  }

  public void outputError(String errorString) {
    for (int i = 0; i < listeners.length; i++) {
      listeners[i].outputError(delegate, errorString);
    }

    delegate.outputError(errorString);
  }

  public void outputInfo(char level, String infoString) {
    for (int i = 0; i < listeners.length; i++) {
      listeners[i].outputInfo(delegate, level, infoString);
    }

    delegate.outputInfo(level, infoString);
  }

  public void outputStat(Map<String, ?> data) {
    delegate.outputStat(data);
  }

  public void outputText(byte[] data) {
    delegate.outputText(data);
  }

  public IStatus getStatus() {
    return delegate.getStatus();
  }

  public String getCommand() {
    return delegate.getCommand();
  }
}
